using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using Ghasam.Business.DAO;
using Spring.Transaction.Interceptor;

namespace Ghasam.Business.Services.Impl
{
    public class EmployeeService : IEmployeeService
    {
        private IJobTitleDao iJobTitleDao;
        private IPaymentFrequencyDao iPaymentFerquencyDao;
        private IEducationDao iEducationDao;
        private IEmployeeDao iEmployeeDao;

        public IJobTitleDao IJobTitleDao
        {
            set { iJobTitleDao = value; }
            get { return iJobTitleDao; }

        }

        public IPaymentFrequencyDao IPaymentFerquencyDao
        {
            set { iPaymentFerquencyDao = value; }
            get { return iPaymentFerquencyDao; }

        }

        public IEducationDao IEducationDao
        {
            set { iEducationDao = value; }
            get { return iEducationDao; }

        }

        public IEmployeeDao IEmployeeDao
        {
            set { iEmployeeDao = value; }
            get { return iEmployeeDao; }

        }

        [Transaction(ReadOnly = false)]
        public Employee EmployeeSaveOrUpadate(int? empId, int educationId, int paymentFrequencyId, int jobTitleId, DateTime birthDay, DateTime joinedDate, DateTime? leftDate, string firstName, string lastName, string address, string phone, string ssn, string bornPlace, string identityNumber, bool gender, bool insurance, bool married, bool isFormal, bool isActive, bool isDeleted, string description, float exteraPay, string insuranceNo, DateTime modifyDate)
        {
            Employee employee = new Employee();
            if (empId.HasValue && empId.Value > 0)
            {
                employee = IEmployeeDao.FindById(empId);
            }
            employee.Address = address;
            employee.BirthDay = birthDay;
            employee.Description = description;
            employee.FirstName = firstName;
            employee.LastName = lastName;
            employee.Phone = phone;
            employee.SSN = ssn;
            employee.BornPlace = bornPlace;
            employee.LeftDate = leftDate;
            employee.Insurance = insurance;
            employee.IdentityNumber = identityNumber;
            employee.Married = married;
            employee.Gender = gender;
            employee.IsActive = isActive;
            employee.IsDeleted = isDeleted;
            employee.IsFormal = isFormal;
            employee.JoinedDate = joinedDate;
            employee.ExtraPay = exteraPay;
            employee.InsuranceNo = insuranceNo;
            employee.ModifyDate = modifyDate;
            JobTitle jobTitle = IJobTitleDao.FindById(jobTitleId);
            employee.JobTitle = jobTitle;
            EmployeePaymentFrequency paymentF = IPaymentFerquencyDao.FindById(paymentFrequencyId);
            employee.EmployeePaymentFrequency = paymentF;
            Education education = IEducationDao.FindById(educationId);
            employee.Education = education;
           return IEmployeeDao.SaveOrUpdate(employee);
        }

        [Transaction(ReadOnly = false)]
        public void EmployeeUpadate(int empId, DateTime? leftDate, string firstName, string lastName, bool insurance, bool isFormal, bool isActive, bool isDeleted, DateTime modifyDate)
        {
            Employee employee = new Employee();
            employee=IEmployeeDao.FindById(empId);
            //employee.Address = address;
            //employee.BirthDay = birthDay;
            //employee.Description = description;
            employee.FirstName = firstName;
            employee.LastName = lastName;
            employee.LeftDate = leftDate;
            employee.Insurance = insurance;
            employee.IsActive = isActive;
            employee.IsDeleted = isDeleted;
            employee.IsFormal = isFormal;
            employee.ModifyDate = modifyDate;
            //JobTitle jobTitle = IJobTitleDao.FindById(jobTitleId);
            //employee.JobTitle = jobTitle;
            //EmployeePaymentFrequency paymentF = IPaymentFerquencyDao.FindById(paymentFrequencyId);
            //employee.EmployeePaymentFrequency = paymentF;

            IEmployeeDao.SaveOrUpdate(employee);
        }

        public IList<Employee> SearchEmployee(string firstName, string lastName, int? empId, DateTime? joinedDate, bool? isFormal)
        { return IEmployeeDao.searchEmployee(firstName, lastName, empId, joinedDate, isFormal); }

        public Employee GetById(int employeeId)
        {
            return IEmployeeDao.FindById(employeeId);
        }

        public IList<JobTitle> FindAllJobTitle()
        {
            return IJobTitleDao.FindAll();
        }
        public IList<Education> FindAllEducation()
        {
            return IEducationDao.FindAll();
        }
        public IList<EmployeePaymentFrequency> FindAllPaymentFrequency()
        {
            return IPaymentFerquencyDao.FindAll();
        }
    }
}
